package com.midea.ai.air.ui.device.product.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.midea.ai.air.R;

/**
 * 功能按钮公用view
 *
 * @author tanchuo 2016/3/22
 */
public class FuncItemView extends RelativeLayout
{
    private Context context;
    public ToggleButton btn;
    private TextView text;
    private boolean checked;

    public FuncItemView(Context context)
    {
        super(context);
        init(context, null, 0);
    }

    public FuncItemView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        init(context, attrs, 0);
    }

    public FuncItemView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        init(context, attrs, 0);
    }

    private void init(Context context, AttributeSet attrs, int i)
    {
        View.inflate(context, R.layout.device_func_item, this);
        this.context = context;
        btn = (ToggleButton) findViewById(R.id.func_btn);
        text = (TextView) findViewById(R.id.func_text);

    }

    public void setText(String textString)
    {
        text.setText(textString);
    }

    public void setTextVisible(boolean visible)
    {
        if (visible)
        {
            text.setVisibility(View.VISIBLE);
        } else
        {
            text.setVisibility(View.GONE);
        }
    }

    public void setOnCheckChangeListener(OnClickListener listener)
    {
        btn.setOnClickListener(listener);
    }

    public void setStatus(boolean checked)
    {
        this.checked = checked;
        btn.setChecked(checked);
    }

    public boolean getStatus()
    {
        return checked;
    }

    public void setBackGroundRes(int resid)
    {
        btn.setBackgroundResource(resid);
    }

    @SuppressLint("NewApi")
    public void setTextAlpha(int alpha)
    {
        text.setAlpha(alpha);
    }
}
